package com.qf.ayc.config;

import com.qf.ayc.config.ResultVo;
//import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExHandler {
    //扔出的是TokenException错误类型的方法
    @ExceptionHandler(TokenException.class)
    public ResultVo handleTokenEx(TokenException tokenException){
        tokenException.printStackTrace();
        return new ResultVo(tokenException.getCode(),tokenException.getTokenMsg(),null);
    }
    //普通错误的方法
    @ExceptionHandler(Exception.class)
    public ResultVo handleEx(Exception exception){
        exception.printStackTrace();//将异常对象的所有信息都打印到控制台
        ResultVo resultVo = new ResultVo();
        resultVo.setCode(-1);
        resultVo.setMsg(exception.getMessage());
        return resultVo;
    }
}
